#!/usr/bin/python

import logging
from karaoke import Karaoke
from web_server import WebServer

CONFIG_FILE='karaoke.cfg'

# Default configuration
config = {
    'port': '8000',
    'singer_subdir_depth': '0',
    'path': 'mtv',
}

logging.basicConfig(level=logging.INFO,
                    format="%(asctime)s %(levelname)s %(message)s")

# Read the config file
for line in open(CONFIG_FILE, 'r'):
    line = line.strip()
    if not line or line.startswith('#'):
        continue
    eq = line.find('=')
    if eq != -1:
        key = line[0:eq].strip()
        value = line[eq+1:].strip()
    else:
        key = line
        value = ''
    config[key] = value

server = WebServer(config, Karaoke(config))
try:
    server.serve_forever()
except KeyboardInterrupt:
    server.shutdown()
